package org.finesys.common.database.core.enums;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.util.Arrays;

@Getter
@RequiredArgsConstructor
public enum DsJdbcUrlEnum {
    /**
     * MYSQL数据库
     */
    MYSQL("mysql", "jdbc:mysql://%s:%s/%s?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimeZoneShift=true&useLegacyDatetimeCode=false&allowMulitQueries=true&allowPublicKeyRetrieval=true", "select 1", "com.mysql.cj.jdbc.Driver", "mysql8链接"),
    /**
     * PG数据库
     */
    PGSQL("pg", "jdbc:postgresql://%s:%s/%s", "select 1", "org.postgresql.Driver", "postgresql链接"),
    /**
     * SQL Server数据库
     */
    MSSQL("mssql", "jdbc:sqlserver://%s:%s;database=%s;characterEncoding=UTF-8", "select 1", "com.microsoft.sqlserver.jdbc.SQLServerDriver", "sqlserver 链接"),
    /**
     * oracle数据库
     */
    ORACLE("oracle", "jdbc:oracle:thin:@%s:%s:%s", "select 1 from dual", "oracle.jdbc.driver.OracleDriver", "oracle 链接"),

    /**
     * 达梦数据库
     */
    DM("dm", "jdbc:dm://%s:%s/%s", "select 1 from dual", "dm.jdbc.driver.DmDriver", "达梦链接"),
    /**
     * DB2数据库
     */
    DB2("db2", "jdbc:db2://%s:%s/%s", "select 1 from sysibm.sysdummy", "com.ibm.db2.jcc.DB2Driver", "DB2 TYPE4 链接"),
    /**
     * 瀚高数据库
     */
    HIGHGO("highgo", "jdbc:highgo://%s:%s/%s", "select 1", "com.highgo.jdbc.Driver", "瀚高链接"),

    ;
    private final String dbName;
    private final String url;
    private final String validationQuery;
    private final String driverClassName;
    private final String description;

    /**
     * 获取数据库URL信息
     */
    public static DsJdbcUrlEnum get(String dsType) {
        return Arrays.stream(DsJdbcUrlEnum.values()).filter(dsJdbcUrlEnum -> dsJdbcUrlEnum.getDbName().equals(dsType)).findFirst().get();
    }

}
